package org.giovanolli.mumi.dao.impl;

import org.giovanolli.mumi.dao.BillDao;
import org.giovanolli.mumi.entities.Bill;
import org.giovanolli.mumi.entities.filter.BillFilter;
import org.giovanolli.mumi.entities.filter.EntityFilter;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * The Class BillDaoImpl.
 */
@Repository("billDao")
public class BillDaoImpl extends HibernateDao<Bill> implements BillDao {

	@Override
	protected DetachedCriteria fillCriteria(EntityFilter<Bill> filter, DetachedCriteria criteria) {
		final BillFilter entityFilter = (BillFilter) filter;

		if (filter != null) {
			if (entityFilter.getPatient() != null) {
				criteria.add(Restrictions.eq("patient", entityFilter.getPatient()));
			}
		}
		return criteria;
	}
}
